package module.location;

import android.location.*;
import android.os.Bundle;

public class LocationIdentifier implements LocationListener
{
	private LocationManager locationManager;
	private Location currentLocation;
	
	public LocationIdentifier(LocationManager locationManager)
	{
		this.locationManager = locationManager;
	}
	
	public void startLocationSearching()
	{
		this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
		this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
	}
	
	public void stopLocationSearching()
	{
		this.locationManager.removeUpdates(this);
	}
	
	@Override
	public void onLocationChanged(Location location)
	{
		if (LocationChecker.newLocationIsBetter(currentLocation, location))
		{
	    	CoordinatesHandler.getCoordinatesHandler().fireCoordinatesEvent(new Coordinates(location.getLongitude(), location.getLatitude(), location.getAccuracy()));
		}
	}

	@Override
	public void onProviderDisabled(String provider)
	{ }

	@Override
	public void onProviderEnabled(String provider)
	{ }

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras)
	{ }
}

